﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Sunny.UI;
namespace Ui
{
    public partial class Form4 : UIForm
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName.Trim();
                List<string> list = new List<string>(File.ReadAllLines(openFileDialog1.FileName.Trim()));
                foreach (string line in list)
                {
                    if (line.Substring(0, 1) == "#")
                    {
                        //Console.WriteLine(line);
                        string[] vs = line.Substring(1, line.Length - 2).Split('!');
                        foreach (var item in vs)
                        {
                            string[] vs1 = item.Split('@');
                            Console.WriteLine(vs1[1]);
                            comboBox1.Items.Add(vs1[0]);
                        }
                    }
                }
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if(textBox2.Text != "")
            {
                List<string> list = new List<string>(File.ReadAllLines(openFileDialog1.FileName.Trim()));
                foreach (string line in list)
                {
                    if (line.Substring(0, 1) == "#")
                    {
                        string[] vs = line.Substring(1, line.Length - 2).Split('!');
                        dataGridView1.ColumnCount = vs.Length;

                        int n = 0;
                        foreach (var item in vs)
                        {
                            string[] vs1 = item.Split('@');
                            Console.WriteLine(vs1.Length);
                            dataGridView1.Columns[n].Name = vs1[0];
                            dataGridView1.Columns[n].Width = dataGridView1.Width / vs.Length;
                            n += 1;
                        }
                    }
                    else if (line.Substring(0, 1) == "$")
                    {
                        string[] vs = line.Substring(1, line.Length - 2).Split('%');
                        if (vs[comboBox1.SelectedIndex] == textBox2.Text)
                        {
                            dataGridView1.Rows.Add(vs);
                        }
                    }
                }
            }
        }
    }
}
